function SoundManager(maxSounds) {
	var soundPool = new Array();
	var MAX_SOUNDS = maxSounds;
	
	this.supportedAudioFormat = function(audio) {
		var returnExtension = "";
		if (audio.canPlayType("audio/ogg") =="probably" || audio.canPlayType("audio/ogg") == "maybe") {
			returnExtension = "ogg";
		} else if(audio.canPlayType("audio/wav") =="probably" || audio.canPlayType("audio/wav") == "maybe") {
			returnExtension = "wav";
		} else if(audio.canPlayType("audio/mpeg3") == "probably" || audio.canPlayType("audio/mpeg3") == "maybe") {
			returnExtension = "mp3";
		} else if(audio.canPlayType("audio/xmpeg3") == "probably" || audio.canPlayType("audio/xmpeg3") == "maybe") {
			returnExtension = "mp3";
		}
		
		return returnExtension;
		
	}
	
	this.addSound = function(name,copies) {
		for (var i=0;i < copies;i++) {
			var tempSound = document.createElement("audio");
			document.body.appendChild(tempSound);
			audioType = this.supportedAudioFormat(tempSound);
			tempSound.addEventListener("canplaythrough",soundLoaded,false);
			tempSound.setAttribute("src", name + "." + audioType);
			soundPool.push({name:name, element:tempSound, played:false});
		}
	}
	
	function soundLoaded(e){
	}
	
	this.playSound = function(sound,volume,loop) {
	
		var soundFound = false;
		var soundIndex = 0;
		var tempSound;
		
		if (soundPool.length> 0) {
			while (!soundFound && soundIndex < soundPool.length) {
			
				var tSound = soundPool[soundIndex];
				Debugger.log("tSound.name:" + tSound.name);
				if ((tSound.element.ended || !tSound.played) && tSound.name == sound) {
					soundFound = true;
					tSound.played = true;
				} else {
					soundIndex++;
				}
		
			}
		}
		if (soundFound) {
			tempSound = soundPool[soundIndex].element;
			tempSound.volume = volume;
			tempSound.loop = loop;
			tempSound.play();
			
		} else if (soundPool.length < MAX_SOUNDS){
			tempSound = document.createElement("audio");
			tempSound.setAttribute("src", sound + "." + audioType);
			tempSound.volume = volume;
			tempSound.play();
			tempSound.loop = loop;
			soundPool.push({name:sound, element:tempSound, type:audioType, played:true});
		}

	}
	
	this.setMuted = function (value) {
		for (var i=0;i < soundPool.length;i++) {
			soundPool[i].element.muted = value;
		}
	
	}
	

}
